package com.quotes.ui;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.log4j.AppenderSkeleton;
import org.apache.log4j.spi.LoggingEvent;

public class LoggingPanelAppender extends AppenderSkeleton 
{
	private LoggingTarget target;
	private DateFormat dformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss,SSS");
	
	public LoggingPanelAppender(LoggingTarget target) {
		this.target = target;
	}
	
	@Override
	protected void append(LoggingEvent event) {
		String dateString = dformat.format(new Date(event.timeStamp)); 
		target.append(dateString + ": " + event.getLoggerName() + " -- " + event.getMessage().toString());
	}

	@Override
	public void close() {
	}

	@Override
	public boolean requiresLayout() {
		return false;
	}

}
